package com.erp.itm.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.erp.common.controller.BaseController;
import com.erp.itm.domain.PaytypeDO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.erp.itm.domain.ProjectCustnameDO;
import com.erp.itm.service.ProjectCustnameService;
import com.erp.common.utils.PageUtils;
import com.erp.common.utils.Query;
import com.erp.common.utils.R;

/**
 * 
 * 
 * @author Eric
 * @email shiliang900713@163.com
 * @date 2020-01-03 17:00:48
 */
 
@Controller
@RequestMapping("/itm/projectCustname")
public class ProjectCustnameController extends BaseController {
	@Autowired
	private ProjectCustnameService projectCustnameService;
	
	@GetMapping()
	String ProjectCustname(){
	    return "itm/projectCustname/projectCustname";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ProjectCustnameDO> projectCustnameList = projectCustnameService.list(query);
		int total = projectCustnameService.count(query);
		PageUtils pageUtils = new PageUtils(projectCustnameList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "itm/projectCustname/add";
	}

	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Long id,Model model){
		ProjectCustnameDO projectCustname = projectCustnameService.get(id);
		model.addAttribute("projectCustname", projectCustname);
	    return "itm/projectCustname/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( ProjectCustnameDO projectCustname){
		projectCustname.setCreateTime(new Date());
		projectCustname.setCreateUserid(getUserId());
		projectCustname.setCreateUsername(getUsername());
		if(projectCustnameService.save(projectCustname)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( ProjectCustnameDO projectCustname){
		projectCustnameService.update(projectCustname);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Long id){
		if(projectCustnameService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
            * 删除
	 */
    @PostMapping( "/batchRemove")
    @ResponseBody
    public R remove(@RequestParam("ids[]") Long[] ids){
        projectCustnameService.batchRemove(ids);
        return R.ok();
    }

    @ResponseBody
    @GetMapping("/customlist")
    public List<ProjectCustnameDO> customList(){
        //查询列表数据
        List<ProjectCustnameDO> custnameDOList = projectCustnameService.list(null);
        return custnameDOList;
    }


}
